package com.wabbei.fenxiao.action; 
  
import java.util.HashSet;
import java.util.Set;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.taobao.api.internal.stream.Configuration;
import com.taobao.api.internal.stream.TopCometStream;
import com.taobao.api.internal.stream.TopCometStreamFactory;
import com.taobao.api.internal.stream.TopCometStreamRequest;
public class MyListener implements ServletContextListener {  
    private MyThread myThread;  
	
    public void contextDestroyed(ServletContextEvent e) {  
        if (myThread != null && myThread.isInterrupted()) {  
            myThread.interrupt();  
        }  
    }  
  
    public void contextInitialized(ServletContextEvent e) {  
        String str = null;  
        if (str == null && myThread == null) {  
            myThread = new MyThread();  
            myThread.start();  
        }  
    }  
}  
class MyThread extends Thread {
	private String url = "http://stream.api.taobao.com/stream";
	private String appkey = data.appkey;
	private String secret = data.secret;
    public void run() {  
		Configuration conf = new Configuration(appkey,secret,null);
		conf.setConnectUrl(url);
		TopCometStream stream = new TopCometStreamFactory(conf).getInstance();
		stream.setConnectionListener(new ConnectionLifeCycleListenerImpl());
		stream.setMessageListener(new TopCometMessageListenerImpl());
		stream.start();
    } 
} 
